{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "986f101a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ccb197ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"서울특별시 광진구_연령별인구현황_20230101.csv\", encoding= 'cp949')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d74883ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = df.set_index(keys = '연령')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a66a65ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = df.drop(['데이터기준일자'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "08446bbf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>광진구</th>\n",
       "      <th>중곡제1동</th>\n",
       "      <th>중곡제2동</th>\n",
       "      <th>중곡제3동</th>\n",
       "      <th>중곡제4동</th>\n",
       "      <th>능동</th>\n",
       "      <th>구의제1동</th>\n",
       "      <th>구의제2동</th>\n",
       "      <th>구의제3동</th>\n",
       "      <th>광장동</th>\n",
       "      <th>자양제1동</th>\n",
       "      <th>자양제2동</th>\n",
       "      <th>자양제3동</th>\n",
       "      <th>자양제4동</th>\n",
       "      <th>화양동</th>\n",
       "      <th>군자동</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>연령</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0세</th>\n",
       "      <td>1198</td>\n",
       "      <td>56</td>\n",
       "      <td>67</td>\n",
       "      <td>61</td>\n",
       "      <td>83</td>\n",
       "      <td>53</td>\n",
       "      <td>83</td>\n",
       "      <td>76</td>\n",
       "      <td>148</td>\n",
       "      <td>89</td>\n",
       "      <td>66</td>\n",
       "      <td>122</td>\n",
       "      <td>143</td>\n",
       "      <td>58</td>\n",
       "      <td>35</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1세</th>\n",
       "      <td>1334</td>\n",
       "      <td>67</td>\n",
       "      <td>68</td>\n",
       "      <td>70</td>\n",
       "      <td>112</td>\n",
       "      <td>46</td>\n",
       "      <td>87</td>\n",
       "      <td>127</td>\n",
       "      <td>147</td>\n",
       "      <td>113</td>\n",
       "      <td>54</td>\n",
       "      <td>110</td>\n",
       "      <td>187</td>\n",
       "      <td>57</td>\n",
       "      <td>27</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2세</th>\n",
       "      <td>1270</td>\n",
       "      <td>57</td>\n",
       "      <td>60</td>\n",
       "      <td>65</td>\n",
       "      <td>106</td>\n",
       "      <td>53</td>\n",
       "      <td>70</td>\n",
       "      <td>110</td>\n",
       "      <td>137</td>\n",
       "      <td>142</td>\n",
       "      <td>57</td>\n",
       "      <td>110</td>\n",
       "      <td>163</td>\n",
       "      <td>56</td>\n",
       "      <td>26</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3세</th>\n",
       "      <td>1483</td>\n",
       "      <td>63</td>\n",
       "      <td>82</td>\n",
       "      <td>61</td>\n",
       "      <td>100</td>\n",
       "      <td>49</td>\n",
       "      <td>84</td>\n",
       "      <td>141</td>\n",
       "      <td>154</td>\n",
       "      <td>169</td>\n",
       "      <td>76</td>\n",
       "      <td>136</td>\n",
       "      <td>198</td>\n",
       "      <td>73</td>\n",
       "      <td>27</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4세</th>\n",
       "      <td>1479</td>\n",
       "      <td>54</td>\n",
       "      <td>97</td>\n",
       "      <td>60</td>\n",
       "      <td>113</td>\n",
       "      <td>47</td>\n",
       "      <td>112</td>\n",
       "      <td>143</td>\n",
       "      <td>160</td>\n",
       "      <td>183</td>\n",
       "      <td>65</td>\n",
       "      <td>128</td>\n",
       "      <td>165</td>\n",
       "      <td>64</td>\n",
       "      <td>28</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>106세</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>107세</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108세</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109세</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>110세 이상</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>111 rows × 16 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          광진구  중곡제1동  중곡제2동  중곡제3동  중곡제4동  능동  구의제1동  구의제2동  구의제3동  광장동  \\\n",
       "연령                                                                        \n",
       "0세       1198     56     67     61     83  53     83     76    148   89   \n",
       "1세       1334     67     68     70    112  46     87    127    147  113   \n",
       "2세       1270     57     60     65    106  53     70    110    137  142   \n",
       "3세       1483     63     82     61    100  49     84    141    154  169   \n",
       "4세       1479     54     97     60    113  47    112    143    160  183   \n",
       "...       ...    ...    ...    ...    ...  ..    ...    ...    ...  ...   \n",
       "106세        0      0      0      0      0   0      0      0      0    0   \n",
       "107세        1      0      0      0      0   0      0      0      0    0   \n",
       "108세        0      0      0      0      0   0      0      0      0    0   \n",
       "109세        0      0      0      0      0   0      0      0      0    0   \n",
       "110세 이상     4      0      0      0      2   0      0      1      0    0   \n",
       "\n",
       "         자양제1동  자양제2동  자양제3동  자양제4동  화양동  군자동  \n",
       "연령                                             \n",
       "0세          66    122    143     58   35   58  \n",
       "1세          54    110    187     57   27   62  \n",
       "2세          57    110    163     56   26   58  \n",
       "3세          76    136    198     73   27   70  \n",
       "4세          65    128    165     64   28   60  \n",
       "...        ...    ...    ...    ...  ...  ...  \n",
       "106세         0      0      0      0    0    0  \n",
       "107세         0      0      0      0    0    1  \n",
       "108세         0      0      0      0    0    0  \n",
       "109세         0      0      0      0    0    0  \n",
       "110세 이상      0      1      0      0    0    0  \n",
       "\n",
       "[111 rows x 16 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ac79366b",
   "metadata": {},
   "outputs": [],
   "source": [
    "table = pd.DataFrame(index = ['유아(만0~7세)','노인(만65세이상)', '총인구'],columns = df.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b57fb0f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i,column in enumerate(table.columns) :\n",
    "    value_list = []\n",
    "    kids = df.iloc[:8,i].sum()\n",
    "    silvers = df.iloc[65:,i].sum()\n",
    "    total = df.iloc[:,i].sum()\n",
    "    value_list.append(kids)\n",
    "    value_list.append(silvers)\n",
    "    value_list.append(total)\n",
    "    table[column] = value_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "66962b98",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>광진구</th>\n",
       "      <th>중곡제1동</th>\n",
       "      <th>중곡제2동</th>\n",
       "      <th>중곡제3동</th>\n",
       "      <th>중곡제4동</th>\n",
       "      <th>능동</th>\n",
       "      <th>구의제1동</th>\n",
       "      <th>구의제2동</th>\n",
       "      <th>구의제3동</th>\n",
       "      <th>광장동</th>\n",
       "      <th>자양제1동</th>\n",
       "      <th>자양제2동</th>\n",
       "      <th>자양제3동</th>\n",
       "      <th>자양제4동</th>\n",
       "      <th>화양동</th>\n",
       "      <th>군자동</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>유아(만0~7세)</th>\n",
       "      <td>12283</td>\n",
       "      <td>480</td>\n",
       "      <td>692</td>\n",
       "      <td>521</td>\n",
       "      <td>882</td>\n",
       "      <td>395</td>\n",
       "      <td>730</td>\n",
       "      <td>1104</td>\n",
       "      <td>1280</td>\n",
       "      <td>1717</td>\n",
       "      <td>578</td>\n",
       "      <td>1020</td>\n",
       "      <td>1577</td>\n",
       "      <td>509</td>\n",
       "      <td>248</td>\n",
       "      <td>550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>노인(만65세이상)</th>\n",
       "      <td>53737</td>\n",
       "      <td>2619</td>\n",
       "      <td>3410</td>\n",
       "      <td>2937</td>\n",
       "      <td>5411</td>\n",
       "      <td>1668</td>\n",
       "      <td>3312</td>\n",
       "      <td>4502</td>\n",
       "      <td>4368</td>\n",
       "      <td>3986</td>\n",
       "      <td>3621</td>\n",
       "      <td>4196</td>\n",
       "      <td>4467</td>\n",
       "      <td>3749</td>\n",
       "      <td>2332</td>\n",
       "      <td>3159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>총인구</th>\n",
       "      <td>337416</td>\n",
       "      <td>15299</td>\n",
       "      <td>20999</td>\n",
       "      <td>15945</td>\n",
       "      <td>28035</td>\n",
       "      <td>11180</td>\n",
       "      <td>23387</td>\n",
       "      <td>26043</td>\n",
       "      <td>28211</td>\n",
       "      <td>34168</td>\n",
       "      <td>21862</td>\n",
       "      <td>23946</td>\n",
       "      <td>27553</td>\n",
       "      <td>17926</td>\n",
       "      <td>23437</td>\n",
       "      <td>19425</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               광진구  중곡제1동  중곡제2동  중곡제3동  중곡제4동     능동  구의제1동  구의제2동  구의제3동  \\\n",
       "유아(만0~7세)    12283    480    692    521    882    395    730   1104   1280   \n",
       "노인(만65세이상)   53737   2619   3410   2937   5411   1668   3312   4502   4368   \n",
       "총인구         337416  15299  20999  15945  28035  11180  23387  26043  28211   \n",
       "\n",
       "              광장동  자양제1동  자양제2동  자양제3동  자양제4동    화양동    군자동  \n",
       "유아(만0~7세)    1717    578   1020   1577    509    248    550  \n",
       "노인(만65세이상)   3986   3621   4196   4467   3749   2332   3159  \n",
       "총인구         34168  21862  23946  27553  17926  23437  19425  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "215ce2ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "table.loc['유아비율(%)'] = table.loc['유아(만0~7세)']/table.loc['총인구']*100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "350a8160",
   "metadata": {},
   "outputs": [],
   "source": [
    "table.loc['노인비율(%)'] = table.loc['노인(만65세이상)']/table.loc['총인구']*100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "d7ba1c64",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>유아(만0~7세)</th>\n",
       "      <th>노인(만65세이상)</th>\n",
       "      <th>총인구</th>\n",
       "      <th>유아비율(%)</th>\n",
       "      <th>노인비율(%)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>광진구</th>\n",
       "      <td>12283.0</td>\n",
       "      <td>53737.0</td>\n",
       "      <td>337416.0</td>\n",
       "      <td>3.640313</td>\n",
       "      <td>15.926038</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제1동</th>\n",
       "      <td>480.0</td>\n",
       "      <td>2619.0</td>\n",
       "      <td>15299.0</td>\n",
       "      <td>3.137460</td>\n",
       "      <td>17.118766</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제2동</th>\n",
       "      <td>692.0</td>\n",
       "      <td>3410.0</td>\n",
       "      <td>20999.0</td>\n",
       "      <td>3.295395</td>\n",
       "      <td>16.238869</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제3동</th>\n",
       "      <td>521.0</td>\n",
       "      <td>2937.0</td>\n",
       "      <td>15945.0</td>\n",
       "      <td>3.267482</td>\n",
       "      <td>18.419567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제4동</th>\n",
       "      <td>882.0</td>\n",
       "      <td>5411.0</td>\n",
       "      <td>28035.0</td>\n",
       "      <td>3.146067</td>\n",
       "      <td>19.300874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>능동</th>\n",
       "      <td>395.0</td>\n",
       "      <td>1668.0</td>\n",
       "      <td>11180.0</td>\n",
       "      <td>3.533095</td>\n",
       "      <td>14.919499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>구의제1동</th>\n",
       "      <td>730.0</td>\n",
       "      <td>3312.0</td>\n",
       "      <td>23387.0</td>\n",
       "      <td>3.121392</td>\n",
       "      <td>14.161714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>구의제2동</th>\n",
       "      <td>1104.0</td>\n",
       "      <td>4502.0</td>\n",
       "      <td>26043.0</td>\n",
       "      <td>4.239143</td>\n",
       "      <td>17.286795</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>구의제3동</th>\n",
       "      <td>1280.0</td>\n",
       "      <td>4368.0</td>\n",
       "      <td>28211.0</td>\n",
       "      <td>4.537237</td>\n",
       "      <td>15.483322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>광장동</th>\n",
       "      <td>1717.0</td>\n",
       "      <td>3986.0</td>\n",
       "      <td>34168.0</td>\n",
       "      <td>5.025170</td>\n",
       "      <td>11.665886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>자양제1동</th>\n",
       "      <td>578.0</td>\n",
       "      <td>3621.0</td>\n",
       "      <td>21862.0</td>\n",
       "      <td>2.643857</td>\n",
       "      <td>16.562986</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>자양제2동</th>\n",
       "      <td>1020.0</td>\n",
       "      <td>4196.0</td>\n",
       "      <td>23946.0</td>\n",
       "      <td>4.259584</td>\n",
       "      <td>17.522760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>자양제3동</th>\n",
       "      <td>1577.0</td>\n",
       "      <td>4467.0</td>\n",
       "      <td>27553.0</td>\n",
       "      <td>5.723515</td>\n",
       "      <td>16.212391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>자양제4동</th>\n",
       "      <td>509.0</td>\n",
       "      <td>3749.0</td>\n",
       "      <td>17926.0</td>\n",
       "      <td>2.839451</td>\n",
       "      <td>20.913757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>화양동</th>\n",
       "      <td>248.0</td>\n",
       "      <td>2332.0</td>\n",
       "      <td>23437.0</td>\n",
       "      <td>1.058156</td>\n",
       "      <td>9.950079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>군자동</th>\n",
       "      <td>550.0</td>\n",
       "      <td>3159.0</td>\n",
       "      <td>19425.0</td>\n",
       "      <td>2.831403</td>\n",
       "      <td>16.262548</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       유아(만0~7세)  노인(만65세이상)       총인구   유아비율(%)    노인비율(%)\n",
       "광진구      12283.0     53737.0  337416.0  3.640313  15.926038\n",
       "중곡제1동      480.0      2619.0   15299.0  3.137460  17.118766\n",
       "중곡제2동      692.0      3410.0   20999.0  3.295395  16.238869\n",
       "중곡제3동      521.0      2937.0   15945.0  3.267482  18.419567\n",
       "중곡제4동      882.0      5411.0   28035.0  3.146067  19.300874\n",
       "능동         395.0      1668.0   11180.0  3.533095  14.919499\n",
       "구의제1동      730.0      3312.0   23387.0  3.121392  14.161714\n",
       "구의제2동     1104.0      4502.0   26043.0  4.239143  17.286795\n",
       "구의제3동     1280.0      4368.0   28211.0  4.537237  15.483322\n",
       "광장동       1717.0      3986.0   34168.0  5.025170  11.665886\n",
       "자양제1동      578.0      3621.0   21862.0  2.643857  16.562986\n",
       "자양제2동     1020.0      4196.0   23946.0  4.259584  17.522760\n",
       "자양제3동     1577.0      4467.0   27553.0  5.723515  16.212391\n",
       "자양제4동      509.0      3749.0   17926.0  2.839451  20.913757\n",
       "화양동        248.0      2332.0   23437.0  1.058156   9.950079\n",
       "군자동        550.0      3159.0   19425.0  2.831403  16.262548"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table = table.transpose()\n",
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d63e8674",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>유아(만0~7세)</th>\n",
       "      <th>노인(만65세이상)</th>\n",
       "      <th>총인구</th>\n",
       "      <th>유아비율(%)</th>\n",
       "      <th>노인비율(%)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>자양제4동</th>\n",
       "      <td>509.0</td>\n",
       "      <td>3749.0</td>\n",
       "      <td>17926.0</td>\n",
       "      <td>2.839451</td>\n",
       "      <td>20.913757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제4동</th>\n",
       "      <td>882.0</td>\n",
       "      <td>5411.0</td>\n",
       "      <td>28035.0</td>\n",
       "      <td>3.146067</td>\n",
       "      <td>19.300874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제3동</th>\n",
       "      <td>521.0</td>\n",
       "      <td>2937.0</td>\n",
       "      <td>15945.0</td>\n",
       "      <td>3.267482</td>\n",
       "      <td>18.419567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>자양제2동</th>\n",
       "      <td>1020.0</td>\n",
       "      <td>4196.0</td>\n",
       "      <td>23946.0</td>\n",
       "      <td>4.259584</td>\n",
       "      <td>17.522760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>구의제2동</th>\n",
       "      <td>1104.0</td>\n",
       "      <td>4502.0</td>\n",
       "      <td>26043.0</td>\n",
       "      <td>4.239143</td>\n",
       "      <td>17.286795</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제1동</th>\n",
       "      <td>480.0</td>\n",
       "      <td>2619.0</td>\n",
       "      <td>15299.0</td>\n",
       "      <td>3.137460</td>\n",
       "      <td>17.118766</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>자양제1동</th>\n",
       "      <td>578.0</td>\n",
       "      <td>3621.0</td>\n",
       "      <td>21862.0</td>\n",
       "      <td>2.643857</td>\n",
       "      <td>16.562986</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>군자동</th>\n",
       "      <td>550.0</td>\n",
       "      <td>3159.0</td>\n",
       "      <td>19425.0</td>\n",
       "      <td>2.831403</td>\n",
       "      <td>16.262548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제2동</th>\n",
       "      <td>692.0</td>\n",
       "      <td>3410.0</td>\n",
       "      <td>20999.0</td>\n",
       "      <td>3.295395</td>\n",
       "      <td>16.238869</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>자양제3동</th>\n",
       "      <td>1577.0</td>\n",
       "      <td>4467.0</td>\n",
       "      <td>27553.0</td>\n",
       "      <td>5.723515</td>\n",
       "      <td>16.212391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>광진구</th>\n",
       "      <td>12283.0</td>\n",
       "      <td>53737.0</td>\n",
       "      <td>337416.0</td>\n",
       "      <td>3.640313</td>\n",
       "      <td>15.926038</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>구의제3동</th>\n",
       "      <td>1280.0</td>\n",
       "      <td>4368.0</td>\n",
       "      <td>28211.0</td>\n",
       "      <td>4.537237</td>\n",
       "      <td>15.483322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>능동</th>\n",
       "      <td>395.0</td>\n",
       "      <td>1668.0</td>\n",
       "      <td>11180.0</td>\n",
       "      <td>3.533095</td>\n",
       "      <td>14.919499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>구의제1동</th>\n",
       "      <td>730.0</td>\n",
       "      <td>3312.0</td>\n",
       "      <td>23387.0</td>\n",
       "      <td>3.121392</td>\n",
       "      <td>14.161714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>광장동</th>\n",
       "      <td>1717.0</td>\n",
       "      <td>3986.0</td>\n",
       "      <td>34168.0</td>\n",
       "      <td>5.025170</td>\n",
       "      <td>11.665886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>화양동</th>\n",
       "      <td>248.0</td>\n",
       "      <td>2332.0</td>\n",
       "      <td>23437.0</td>\n",
       "      <td>1.058156</td>\n",
       "      <td>9.950079</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       유아(만0~7세)  노인(만65세이상)       총인구   유아비율(%)    노인비율(%)\n",
       "자양제4동      509.0      3749.0   17926.0  2.839451  20.913757\n",
       "중곡제4동      882.0      5411.0   28035.0  3.146067  19.300874\n",
       "중곡제3동      521.0      2937.0   15945.0  3.267482  18.419567\n",
       "자양제2동     1020.0      4196.0   23946.0  4.259584  17.522760\n",
       "구의제2동     1104.0      4502.0   26043.0  4.239143  17.286795\n",
       "중곡제1동      480.0      2619.0   15299.0  3.137460  17.118766\n",
       "자양제1동      578.0      3621.0   21862.0  2.643857  16.562986\n",
       "군자동        550.0      3159.0   19425.0  2.831403  16.262548\n",
       "중곡제2동      692.0      3410.0   20999.0  3.295395  16.238869\n",
       "자양제3동     1577.0      4467.0   27553.0  5.723515  16.212391\n",
       "광진구      12283.0     53737.0  337416.0  3.640313  15.926038\n",
       "구의제3동     1280.0      4368.0   28211.0  4.537237  15.483322\n",
       "능동         395.0      1668.0   11180.0  3.533095  14.919499\n",
       "구의제1동      730.0      3312.0   23387.0  3.121392  14.161714\n",
       "광장동       1717.0      3986.0   34168.0  5.025170  11.665886\n",
       "화양동        248.0      2332.0   23437.0  1.058156   9.950079"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table.sort_values(by ='노인비율(%)', ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "efc95dda",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>유아(만0~7세)</th>\n",
       "      <th>노인(만65세이상)</th>\n",
       "      <th>총인구</th>\n",
       "      <th>유아비율(%)</th>\n",
       "      <th>노인비율(%)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>자양제3동</th>\n",
       "      <td>1577.0</td>\n",
       "      <td>4467.0</td>\n",
       "      <td>27553.0</td>\n",
       "      <td>5.723515</td>\n",
       "      <td>16.212391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>광장동</th>\n",
       "      <td>1717.0</td>\n",
       "      <td>3986.0</td>\n",
       "      <td>34168.0</td>\n",
       "      <td>5.025170</td>\n",
       "      <td>11.665886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>구의제3동</th>\n",
       "      <td>1280.0</td>\n",
       "      <td>4368.0</td>\n",
       "      <td>28211.0</td>\n",
       "      <td>4.537237</td>\n",
       "      <td>15.483322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>자양제2동</th>\n",
       "      <td>1020.0</td>\n",
       "      <td>4196.0</td>\n",
       "      <td>23946.0</td>\n",
       "      <td>4.259584</td>\n",
       "      <td>17.522760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>구의제2동</th>\n",
       "      <td>1104.0</td>\n",
       "      <td>4502.0</td>\n",
       "      <td>26043.0</td>\n",
       "      <td>4.239143</td>\n",
       "      <td>17.286795</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>광진구</th>\n",
       "      <td>12283.0</td>\n",
       "      <td>53737.0</td>\n",
       "      <td>337416.0</td>\n",
       "      <td>3.640313</td>\n",
       "      <td>15.926038</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>능동</th>\n",
       "      <td>395.0</td>\n",
       "      <td>1668.0</td>\n",
       "      <td>11180.0</td>\n",
       "      <td>3.533095</td>\n",
       "      <td>14.919499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제2동</th>\n",
       "      <td>692.0</td>\n",
       "      <td>3410.0</td>\n",
       "      <td>20999.0</td>\n",
       "      <td>3.295395</td>\n",
       "      <td>16.238869</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제3동</th>\n",
       "      <td>521.0</td>\n",
       "      <td>2937.0</td>\n",
       "      <td>15945.0</td>\n",
       "      <td>3.267482</td>\n",
       "      <td>18.419567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제4동</th>\n",
       "      <td>882.0</td>\n",
       "      <td>5411.0</td>\n",
       "      <td>28035.0</td>\n",
       "      <td>3.146067</td>\n",
       "      <td>19.300874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>중곡제1동</th>\n",
       "      <td>480.0</td>\n",
       "      <td>2619.0</td>\n",
       "      <td>15299.0</td>\n",
       "      <td>3.137460</td>\n",
       "      <td>17.118766</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>구의제1동</th>\n",
       "      <td>730.0</td>\n",
       "      <td>3312.0</td>\n",
       "      <td>23387.0</td>\n",
       "      <td>3.121392</td>\n",
       "      <td>14.161714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>자양제4동</th>\n",
       "      <td>509.0</td>\n",
       "      <td>3749.0</td>\n",
       "      <td>17926.0</td>\n",
       "      <td>2.839451</td>\n",
       "      <td>20.913757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>군자동</th>\n",
       "      <td>550.0</td>\n",
       "      <td>3159.0</td>\n",
       "      <td>19425.0</td>\n",
       "      <td>2.831403</td>\n",
       "      <td>16.262548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>자양제1동</th>\n",
       "      <td>578.0</td>\n",
       "      <td>3621.0</td>\n",
       "      <td>21862.0</td>\n",
       "      <td>2.643857</td>\n",
       "      <td>16.562986</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>화양동</th>\n",
       "      <td>248.0</td>\n",
       "      <td>2332.0</td>\n",
       "      <td>23437.0</td>\n",
       "      <td>1.058156</td>\n",
       "      <td>9.950079</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       유아(만0~7세)  노인(만65세이상)       총인구   유아비율(%)    노인비율(%)\n",
       "자양제3동     1577.0      4467.0   27553.0  5.723515  16.212391\n",
       "광장동       1717.0      3986.0   34168.0  5.025170  11.665886\n",
       "구의제3동     1280.0      4368.0   28211.0  4.537237  15.483322\n",
       "자양제2동     1020.0      4196.0   23946.0  4.259584  17.522760\n",
       "구의제2동     1104.0      4502.0   26043.0  4.239143  17.286795\n",
       "광진구      12283.0     53737.0  337416.0  3.640313  15.926038\n",
       "능동         395.0      1668.0   11180.0  3.533095  14.919499\n",
       "중곡제2동      692.0      3410.0   20999.0  3.295395  16.238869\n",
       "중곡제3동      521.0      2937.0   15945.0  3.267482  18.419567\n",
       "중곡제4동      882.0      5411.0   28035.0  3.146067  19.300874\n",
       "중곡제1동      480.0      2619.0   15299.0  3.137460  17.118766\n",
       "구의제1동      730.0      3312.0   23387.0  3.121392  14.161714\n",
       "자양제4동      509.0      3749.0   17926.0  2.839451  20.913757\n",
       "군자동        550.0      3159.0   19425.0  2.831403  16.262548\n",
       "자양제1동      578.0      3621.0   21862.0  2.643857  16.562986\n",
       "화양동        248.0      2332.0   23437.0  1.058156   9.950079"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table.sort_values(by ='유아비율(%)', ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f5cd2c0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "table.to_csv('kids_silvers_rate.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1959d93d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c9f4376",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dee52aea",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d86af228",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44d596c4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
